<template>
    <div class="content-main">
        <div class="breadcrumb">
            <div class="breadcrumb-icon">
                <img src="./../../assets/images/breadcrumb_icon.png" />
            </div>
            <el-breadcrumb separator="/">
                <el-breadcrumb-item>学生实训统计</el-breadcrumb-item>
            </el-breadcrumb>
            <!-- <bread-crumb-back></bread-crumb-back> -->
        </div>
        <div class="content-box">
            <div class="search-box">
                <div class="search-item">
                    <span class="search-title">学生信息: </span>
                    <el-input type="text" v-model="studentInfoValue" style="float:left; width:72%;"></el-input>
                </div>
                <div class="search-item">
                    <span class="search-title">班级名称: </span>
                    <el-select
                        v-model="classStatusValue"
                        placeholder="请选择班级"
                        value-key="value"
                        style="float:left;">
                        <el-option
                        v-for="item in classStatus"
                        :key="item.value"
                        :label="item.label"
                        :value="item.value">
                        </el-option>
                    </el-select>
                </div>
                <div class="search-item">
                    <el-button type="primary" @click="searchFn">搜索</el-button>
                </div>
            </div>
            <div class="table-content" v-loading="tableLoading">
                <el-table
                :data="tableData"
                border
                style="width: 100%">
                    <el-table-column prop="number" label="序号">
                    </el-table-column>
                    <el-table-column  prop="className" label="班级">
                    </el-table-column>
                    <el-table-column prop="userNumber" label="学号">
                    </el-table-column>
                    <el-table-column prop="userName" label="姓名">
                    </el-table-column>
                    <el-table-column label="操作">
                        <template slot-scope="scope">
                            <router-link :to="{ path: '/teacher/studentTrainingStatisticsView', query: { detailId: scope.row.userId } }">
                                <el-button type="text" size="small">详情</el-button>
                            </router-link>
                        </template>
                    </el-table-column>
                </el-table>
                <el-pagination
                    @size-change="handleSizeChange"
                    @current-change="handleCurrentChange"
                    :current-page="currentPage"
                    :page-size="pagesize"
                    layout="total, prev, pager, next, jumper"
                    :total="totalCount"
                    style="margin-top: 20px; text-align: center;">
                </el-pagination>
            </div>
        </div>
    </div>
</template>

<script>
    import BreadCrumbBack from '@/components/breadCrumbBack.vue'
    export default {
        components: {
            BreadCrumbBack
        },
        data () {
            return {
                classStatus: [
                    {
                        value: '',
                        label: '全部'
                    }
                ],
                classStatusValue: '',
                studentInfoValue: '',
                tableLoading: false,
                tableData: [],
                currentPage: 1,
                pagesize: 10,
                totalCount: 1000
            }
        },
        created () {
            this.init()     //初始化
            this.tableInit()     //初始化
        },
        methods: {
            init(){
                let self = this
                self.$http.get('/dataplatform/common/search/listClassItem').then(response => {
                    let res = response.data
                    if(res.code == '200'){
                        for (let i = 0; i < res.data.classList.length; i++) {
                            let classJson = {}
                            classJson.label = res.data.classList[i].name
                            classJson.value = res.data.classList[i].id
                            self.classStatus.push(classJson)
                        }
                    }else if(res.code == '401'){
                        self.$router.replace({
                            path:'/login'
                        })
                    }else{
                        self.$message.error(res.message)
                    }
                })

            },
            tableInit(){
                let self = this
                self.$http.get('/dataplatform/basis/functions/statistics/t/stuCensusList?pageNum='+self.currentPage+'&pageSize='+self.pagesize+'&classId='+self.classStatusValue+'&userName='+self.studentInfoValue).then(response =>{
                    let res = response.data
                    if(res.code == '200'){
                        self.tableData = res.data.list
                        self.totalCount = res.data.total
                        self.numberFn(self)
                    }else if(res.code == '401'){
                        self.$router.replace({
                            path:'/login'
                        })
                    }else{
                        self.$message.error(res.message)
                    }
                })
            },
            //表格分页
            handleSizeChange: function (size) {
                this.pagesize = size;
            },
            handleCurrentChange: function(currentPage) {
                this.currentPage = currentPage
                this.tableInit()
            },
            numberFn(self) {
                if(self.currentPage == 1){
                    for(let i = 0; i < self.tableData.length; i++){
                        self.tableData[i].number = i + 1;
                    }
                }else if(self.currentPage == 2){
                    for(let i = 0; i < self.tableData.length; i++){
                        self.tableData[i].number = i + 1 + 10;
                    }
                }else if(self.currentPage > 2){
                    for(let i = 0; i < self.tableData.length; i++){
                        self.tableData[i].number = (self.currentPage * self.pagesize) + i + 1;
                    }
                }
            },
            //搜索
            searchFn(){
                this.currentPage = 1
                this.tableInit()
            }
        }
    }
</script>
